package com.code.common.util.annotations;

import com.code.common.util.AsciiUtil;
import com.code.common.util.converts.BeanFieldConverter;

import java.lang.annotation.*;

/**
 * 全角到半角字符的转换
 *
 * @author tangyifei
 */
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface FullToHalf {

    /**
     * 转换器（对类的相关字段进行转换）
     */
    class Converter implements BeanFieldConverter<FullToHalf, String> {

        @Override
        public void initialize(FullToHalf ann) {

        }

        @Override
        public boolean isNeedConvert(String field) {
            return AsciiUtil.existFullChar(field);
        }

        @Override
        public String convert(String field) {
            return AsciiUtil.full2Half(field);
        }
    }
}
